<?php

/**
 * Description of MetadataCollection
 *
 * @author JeyDotC
 */
class MetadataCollection {

    private $metadata = array();

    function __construct(array $metadata = array()) {
        $this->metadata = $metadata;
    }

    public function has($annotation) {
        return $this->annotationExists($this->metadata, $annotation);
    }

    public function hasByMember($member, $annotation) {
        $result = false;
        if(array_key_exists($member, $this->metadata)){
            $result = $this->annotationExists($this->metadata[$member], $annotation);
        }
        
        return $result;
    }

    public function find($annotation) {
        return $this->findAnnotation($this->metadata, $annotation);
    }

    public function findByMember($member, $annotation) {
        $result = "";
        if(array_key_exists($member, $this->metadata)){
            $result = $this->findAnnotation($this->metadata[$member], $annotation);
        }
        
        return $result;
    }

    private function annotationExists(array $annotationList, $annotation) {
        $result = false;

        foreach ($annotationList as $meta) {
            if (strpos((string) $meta, (string) $annotation) === 0) {
                $result = true;
                break;
            }
        }

        return $result;
    }

    private function findAnnotation(array $annotationList, $annotation) {
        $result = "";

        foreach ($annotationList as $meta) {
            if (strpos((string) $meta, (string) $annotation) === 0) {
                $result = $meta;
                break;
            }
        }

        return $result;
    }

}

?>
